package top.yangbuyi.controller.statistics;

import cn.hutool.core.date.DateUtil;
import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import org.apache.dubbo.config.annotation.Reference;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import top.yangbuyi.controller.BaseController;
import top.yangbuyi.dto.RevenueQueryDto;
import top.yangbuyi.vo.AjaxResult;
import top.yangbyi.service.RevenueService;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Map;

@RestController
@RequestMapping("statistics/revenue")
public class RevenueController extends BaseController {


    @Reference
    private RevenueService revenueService;

    @GetMapping("queryAllRevenueData")
    //@HystrixCommand
    public AjaxResult queryAllRevenueData(RevenueQueryDto revenueQueryDto, String beginTime, String endTime){
        //如果没有选择开始日期和结果日期，就查询当天的数据

        if(beginTime==null){
            revenueQueryDto.setQueryDate(new SimpleDateFormat("yyyy-MM-dd").format(new Date()).toString());
        }else{
            revenueQueryDto.setBeginTime(beginTime);
            revenueQueryDto.setEndTime(endTime);
        }
        Map<String,Object> res=this.revenueService.queryAllRevenueData(revenueQueryDto);
        return AjaxResult.success(res);
    }
}
